package com.memo.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentContainer;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;

import com.memo.R;
import com.memo.fragment.fragment_homeone;
import com.memo.fragment.fragment_hometwo;

public class HomeActivity extends AppCompatActivity {
    fragment_homeone fragment_homeone;
    fragment_hometwo fragment_hometwo;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);//设置状态栏字体颜色
        fragment_homeone=new fragment_homeone(findViewById(R.id.viewsearch));
        fragment_hometwo=new fragment_hometwo();

        FragmentManager fragmentManager=getSupportFragmentManager();//创建片段管理器
        FragmentTransaction fragmentContainer=fragmentManager.beginTransaction();
        fragmentContainer.add(R.id.home_framelayout,fragment_homeone);//写fragment到容器
        fragmentContainer.add(R.id.home_framelayout,fragment_hometwo);
        fragmentContainer.commit();//fragment开始执行
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
            switch (keyCode){
                case KeyEvent.KEYCODE_BACK:
                    if (fragment_homeone.recy_adpter.isdeletemodel){
                        fragment_homeone.setdelin(false);
                        fragment_homeone.recy_adpter.isdeletemodel=false;
                        fragment_homeone.recy_adpter.refresh();
                        fragment_homeone.recy_adpter.delall();
                        fragment_hometwo.setvisitly(true);
                    }else {
                        finish();
                    }
                    break;
            }
        return true;
    }
}